﻿using System.Diagnostics;
using RealidadeAumentada.Entidades;

namespace RealidadeAumentada.Servicos.Rastreador
{
    class RastreadorBinario : Rastreador_Principios
    {
        protected object _Buffer;

	    protected bool _Esta_Ligado_Buffer;
        
	    public RastreadorBinario(int i_width, int i_height,int i_raster_type,bool i_is_alloc)
            : base(i_width, i_height, i_raster_type)
	    {
		    if(!ObterInstancia(this._size,i_raster_type,i_is_alloc)){
                throw new Excessao();
		    }
	    }

	    public RastreadorBinario(int i_width, int i_height,bool i_is_alloc)
            :base(i_width,i_height,EBuffer.INT1D_BIN_8)
	    {
            if (!ObterInstancia(this._size, EBuffer.INT1D_BIN_8, i_is_alloc))
            {
                throw new Excessao();
		    }
	    }

        public RastreadorBinario(int i_width, int i_height)
            : base(i_width, i_height, EBuffer.INT1D_BIN_8)
	    {
            if (!ObterInstancia(this._size, EBuffer.INT1D_BIN_8, true))
            {
			    throw new Excessao();
		    }
	    }

	    protected bool ObterInstancia(ETamanho i_size,int i_buf_type,bool i_is_alloc)
	    {
		    switch(i_buf_type)
		    {
                case EBuffer.INT1D_BIN_8:
				    this._Buffer = i_is_alloc?new int[i_size.w*i_size.h]:null;
				    break;
			    default:
				    return false;
		    }
		    this._Esta_Ligado_Buffer=i_is_alloc;
		    return true;
	    }
        public override object ObterBuffer()
	    {
		    return this._Buffer;
	    }
	    
        public override bool TemBuffer()
	    {
		    return this._Buffer!=null;
	    }

        public override void CobrirBuffer(object i_ref_buf)
	    {
		    Debug.Assert(!this._Esta_Ligado_Buffer);
		    this._Buffer=i_ref_buf;
	    }	
    }
}
